package com.ben.notebook.domain;

import com.ben.notebook.infrastructure.util.BusinessRuntimeException;
import com.ben.notebook.infrastructure.util.ErrorMsgEnum;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

/**
 * 备忘录操作前校验
 * @date 2020-12-06
 */
@Service
public class NoteValidateService {

    public void validateCreateNotNull(Note note) {
        if (ObjectUtils.isEmpty(note) || !StringUtils.hasLength(note.getTitle())){
            throw new BusinessRuntimeException(ErrorMsgEnum.REQUIRED_ITEM_EMPTY);
        }
    }

    public void validateUpdateNotNull(Note note) {
        if (ObjectUtils.isEmpty(note) || ObjectUtils.isEmpty(note.getNoteId())
                || !StringUtils.hasLength(note.getTitle())
                || ObjectUtils.isEmpty(note.getCreateTime())){
            throw new BusinessRuntimeException(ErrorMsgEnum.REQUIRED_ITEM_EMPTY);
        }
    }

    public void validateDeleteNotNull(Note note) {
        if (ObjectUtils.isEmpty(note) || ObjectUtils.isEmpty(note.getNoteId())){
            throw new BusinessRuntimeException(ErrorMsgEnum.NOTE_NOT_EXIST);
        }
    }
}
